// 指令名
let title = 'debounce'
// 指令函数
function fun() {
  return {
    // 当被绑定的元素挂载到 DOM 中时……
    mounted(el, binding) {
      let { fun, delay, event = 'click' } = binding.value
      let timer = null
      el.addEventListener(event, function () {
        clearTimeout(timer)
        timer = setTimeout(() => {
          fun.apply(this, arguments)
        }, delay)
      })
    }
  }
}

module.exports = {
  title,
  fun
}
